package offer;

public class SumToTarget {

    public static boolean findNumbersWithSum(int[] data, int length, int sum, int[] results){

        if(data == null || data.length < 2){
            return false;
        }
        int curSum = 0;
        int start = 0;
        int end = data.length -1;
        while(end > start){

            curSum = data[start] + data[end];
            if(curSum == sum){
                results[0] = data[start];
                results[1] = data[end];
                return true;
            }

            if(curSum > sum){
                end --;
            } else {
                start ++;
            }
        }
        return false;
    }
}
